package org.example.server.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.autoconfigure.PageHelperProperties;
import lombok.extern.slf4j.Slf4j;
import org.example.mapper.EmpMapper;
import org.example.pojo.Emp;
import org.example.pojo.LimitPage;
import org.example.server.EmpServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.lang.reflect.Array;
import java.time.LocalDate;
import java.util.List;

@Service
@Slf4j
public class EmpServiceImp implements EmpServer {

    @Autowired
    private EmpMapper empMapper;

    @Override
    public Emp login(Emp emp) {
        return empMapper.login(emp);
    }

    @Override
    public LimitPage page(String name, Short gender, LocalDate begin, LocalDate end, Integer page, Integer pageSize) {
        // 1.设置分页参数
        PageHelper.startPage(page,pageSize);
        // 2.查询数据
        List<Emp> list = empMapper.list(name, gender, begin, end);
        // 3.获取分页数据
        Page<Emp> empPage =(Page<Emp>) list;
        // 封装LimitPage对象
        return new LimitPage( empPage.getTotal(),empPage.getResult());
    }

    @Override
    public void delete(List ids) {
        empMapper.delete(ids);
    }

    @Override
    public void add(Emp emp) {
            empMapper.add(emp);
    }

    @Override
    public Emp getById(Integer id) {
        Emp e = empMapper.getById(id);
        return e;
    }

    @Override
    public void update(Emp emp) {
        empMapper.update(emp);
    }


}
